﻿component
{
	include "../../inc/lib.cfm";
	public any function list(any rc)
	{
		var result = {};
		var offset = (rc.page-1)*rc.rows;
		hql = "from members where " & rc.sqlWhere & rc.sqlSort;
		var result["rows"] = ormExecuteQuery(hql, false, {maxResults=rc.rows, offset=offset});
		var totalhql = "select count(id) as total from members where " & rc.sqlWhere ;
		var result["total"] = ormExecuteQuery(totalhql, true);
		return result;
	}

	//删除操作
	public any function delete(numeric id){
		transaction {
            var members = entityLoadByPk("members", arguments.id);
           	entityDelete(members);
            transactionCommit();
        }
	}


	public any function lock(numeric id){
		transaction {
            var q = entityLoadByPk("members", arguments.id);
            if(q.getState() == 0){
				q.setState(1);
			}else{
				q.setState(0);
			}
           	entitySave(q);
            transactionCommit();
        }
	}

	public any function resetLoginPwd(numeric id){
		transaction {
            var q = entityLoadByPk("members", arguments.id);
			q.setloginpassword(hash('111111'));
           	entitySave(q);
            transactionCommit();
        }
	}

	public any function resetPayPwd(numeric id){
		transaction {
            var q = entityLoadByPk("members", arguments.id);
            q.setpaypassword(hash('111111'));
           	entitySave(q);
            transactionCommit();
        }
	}

	//获取操作
	public any function get(numeric id){
		result = entityLoadByPk("members", arguments.id);
		if(isnull(result)){
			result = false;
		}
		return result;
	}

	//新增操作
	public any function save(any rc){
		transaction {
            var q = entityNew("members");
			include "../../inc/saveandupdatenotcommit.cfm";
			q.setLoginpassword(hash(rc.loginpassword));
            q.setpaypassword(hash(rc.paypassword));
            entitySave(q);
            transactionCommit();
        }
        return q;
	}

	//修改操作
	public any function update(any rc){
		transaction {
            var q = entityLoadByPk("members", rc.id);
			if(q.getLoginpassword() != rc.loginpassword){
				loginpassword = hash(rc.loginpassword);
			}else{
				loginpassword = q.getLoginpassword();
			}

			if(q.getpaypassword() != rc.paypassword){
				paypassword = hash(rc.paypassword);
			}else{
				paypassword = q.getpaypassword();
			}

			include "../../inc/saveandupdatenotcommit.cfm";
			q.setloginpassword(loginpassword);
			q.setpaypassword(paypassword);

			entitySave(q);
            transactionCommit();

        }
        return q;
	}
}